/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			ipgsave.cc
  \date			Feb 2012
  \author		TNick

  \brief		Contains the implementation of IPgSave class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<QDebug>
#include	<QString>

#include	"ipgsave.h"


/*  INCLUDES    ============================================================ */
//
//
//
//
/*  DEFINITIONS    --------------------------------------------------------- */

using namespace PgSave;

/*  DEFINITIONS    ========================================================= */
//
//
//
//
/*  DATA    ---------------------------------------------------------------- */

/*  DATA    ================================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/* ------------------------------------------------------------------------- */
IPgSave::IPgSave	( void )
{
	/* stub */
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
IPgSave::~IPgSave	( void )
{
	/* stub */
}
/* ========================================================================= */




#ifdef	PGSAVE_TESTS

//#include	<pgsave/pgsqs.h>
//#include	<pgsave/pgsxml.h>
#define	VAR1_T	"var_1"
#define	VAR2_T	"variable_%1"

/* ------------------------------------------------------------------------- */
bool				Test_Kb_Blind					(
		IPgSave * inst, QString s_path, void * kb_data )
{
	Q_UNUSED( s_path );
	Q_UNUSED( kb_data );
	Q_UNUSED( inst );
	return false;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
bool				Test_get_numerous	( IPgSave * inst )
{
#define GET_VAR(t,f)	t result = inst->f( QString( VAR2_T ).arg( i ), &b_ok )
	int nr_of_tests = 100;
	int j = 0; int i;
	bool b_ok = true;
	for ( i = 0; i < nr_of_tests; i++ )
	{
		switch( j )	{
		case	0:	{
			GET_VAR(qint64, getLong);
			if ( result != ( ((qint64)i)*0xFFFFFFFF ) ) b_ok = false;
			break;}
		case	1:	{
			GET_VAR(qint32, getInt);
			if ( result != ( (qint32)i*0xFFFF ) ) b_ok = false;
			break;}
		case	2:	{
			GET_VAR(qint16, getShort);
			if ( result != ( (qint16)i*0xFF ) ) b_ok = false;
			break;}
		case	3:	{
			GET_VAR(qint8, getByte);
			if ( result != ( (qint8)i ) ) b_ok = false;
			break;}
		case	4:	{
			GET_VAR(int, getInt);
			if ( result != ( (int)i ) ) b_ok = false;
			break;}
		case	5:	{
			GET_VAR(bool, getBool);
			if ( result != ( true ) ) b_ok = false;
			break;}
		case	6:	{
			GET_VAR(bool, getBool);
			if ( result != ( false ) ) b_ok = false;
			break;}
		case	7:	{
			GET_VAR(char, getByte);
			if ( result != ( (char)i ) ) b_ok = false;
			break;}
		case	8:	{
			GET_VAR(QRgb, getInt);
			if ( result != ( (QRgb)( i*0x010000 + i*0x0100  + i*0x01 ) ) ) b_ok = false;
			break;}
		case	9:	{
			GET_VAR(QColor, getColor);
			if ( result != ( QColor( (QRgb)( i*0x010000 + i*0x0100  + i*0x01 ) ) ) ) b_ok = false;
			break;}
		case	10:	{
			GET_VAR(QString, getStr);
			if ( result != ( QString::number( i ) ) ) b_ok = false;
			break;}
		case	11:	{
			GET_VAR(QString, getStr);
			if ( result != ( VAR1_T ) ) b_ok = false;
			break;}
		case	12:	{
			GET_VAR(qreal, getDouble);
			if ( ! qFuzzyCompare(result, ( i + 0.1234 ) ) ) b_ok = false;
			break;}
		}
		j++; if ( j >= 13) j = 0;
		if ( b_ok == false ) break;
	}
	return b_ok;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void				PgSave::IPgSave_Test_i					(
		IPgSave * inst, int & performed, int & succeded )
{
	QString			Outcm;
	QStringList		sl;
	bool			b_ok;
	bool			b_other_ok;

	for (;;)
	{
		b_ok = false;

		if ( inst->exists(  "/" ) ) break;
		if ( inst->exists(  "/Cogito/ergo/sum" ) ) break;


		if ( inst->path().isEmpty() == true ) break;
		if ( inst->path() != "/" ) break;

		inst->path( sl );
		if ( sl.count() != 0 ) break;

		inst->setPath( "/header" );
		if ( inst->exists(  "/header" ) ) break;

		if ( inst->path().isEmpty() == true ) break;
		if ( inst->path() != "/header" ) break;
		inst->path( sl );
		if ( sl.count() != 1 ) break;
		if ( sl.at( 0 ) != "header" ) break;

		inst->setPath( "/tree/of/life" );
		if ( inst->exists(  "/tree/of/life" ) ) break;

		if ( inst->path().isEmpty() == true ) break;
		if ( inst->path() != "/tree/of/life" ) break;
		inst->path( sl );
		if ( sl.count() != 3 ) break;
		if ( sl.at( 0 ) != "tree" ) break;
		if ( sl.at( 1 ) != "of" ) break;
		if ( sl.at( 2 ) != "life" ) break;

		inst->cdUp();
		if ( inst->exists(  "/tree/of" ) ) break;

		if ( inst->path().isEmpty() == true ) break;
		if ( inst->path() != "/tree/of" ) break;
		inst->path( sl );
		if ( sl.count() != 2 ) break;
		if ( sl.at( 0 ) != "tree" ) break;
		if ( sl.at( 1 ) != "of" ) break;

		inst->cdUp();
		if ( inst->exists(  "/tree" ) ) break;

		if ( inst->path().isEmpty() == true ) break;
		if ( inst->path() != "/tree" ) break;
		inst->path( sl );
		if ( sl.count() != 1 ) break;
		if ( sl.at( 0 ) != "tree" ) break;

		inst->cdUp();
		if ( inst->exists(  "/" ) ) break;

		if ( inst->path().isEmpty() == true ) break;
		if ( inst->path() != "/" ) break;
		inst->path( sl );
		if ( sl.count() != 0 ) break;

		inst->setPath( "/tree/of/life" );

		if ( inst->path().isEmpty() == true ) break;
		if ( inst->path() != "/tree/of/life" ) break;
		inst->path( sl );
		if ( sl.count() != 3 ) break;
		if ( sl.at( 0 ) != "tree" ) break;
		if ( sl.at( 1 ) != "of" ) break;
		if ( sl.at( 2 ) != "life" ) break;

		inst->cdUp( 3 );

		if ( inst->path().isEmpty() == true ) break;
		if ( inst->path() != "/" ) break;
		inst->path( sl );
		if ( sl.count() != 0 ) break;


		inst->setPath( "/tree/of/life" );

		if ( inst->path().isEmpty() == true ) break;
		if ( inst->path() != "/tree/of/life" ) break;
		inst->path( sl );
		if ( sl.count() != 3 ) break;
		if ( sl.at( 0 ) != "tree" ) break;
		if ( sl.at( 1 ) != "of" ) break;
		if ( sl.at( 2 ) != "life" ) break;

		inst->cdUp( 2 );

		if ( inst->path().isEmpty() == true ) break;
		if ( inst->path() != "/tree" ) break;
		inst->path( sl );
		if ( sl.count() != 1 ) break;
		if ( sl.at( 0 ) != "tree" ) break;

		inst->cdUp( 200 );

		if ( inst->path().isEmpty() == true ) break;
		if ( inst->path() != "/" ) break;
		inst->path( sl );
		if ( sl.count() != 0 ) break;



		b_ok = true;
		break;
	}
	TEST_RESULT( b_ok , " - current path" );


	for(;;)
	{
		if ( inst->countKb() != 0 ) break;

		inst->appendKb( "test_generic", Test_Kb_Blind );
		if ( inst->countKb() != 1 ) break;

		if ( inst->removeKb( "wrong_input" ) == true) break;
		if ( inst->removeKb( "test_generic" ) == false) break;
		if ( inst->removeKb( "wrong_input" ) == true) break;

		if ( inst->countKb() != 0 ) break;

		b_ok = true; break;
	}
	TEST_RESULT( b_ok , " - generic callback for blind loading " );


	b_ok = false;
	int i;
	for(;;)
	{
		if ( inst->set( VAR1_T, 1 ) == false ) break;

		i = inst->getInt( VAR1_T, &b_other_ok );
		if  ( b_other_ok == false ) break;
		if  ( i != 1 ) break;

		b_ok = true; break;
	}
	TEST_RESULT( b_ok , " - value saved inside instance" );

#define	SET_VAR(v)	if ( inst->set( QString( VAR2_T ).arg( i ), v ) == false ) b_ok = false

	int nr_of_tests = 100;
	int j = 0;
	b_ok = true;
	for ( i = 0; i < nr_of_tests; i++ )
	{
		switch( j )	{
		case	0:	{
			SET_VAR( ((qint64)i)*0xFFFFFFFF );
			break;}
		case	1:	{
			SET_VAR( (qint32)i*0xFFFF );
			break;}
		case	2:	{
			SET_VAR( (qint16)i*0xFF );
			break;}
		case	3:	{
			SET_VAR( (qint8)i );
			break;}
		case	4:	{
			SET_VAR( (int)i );
			break;}
		case	5:	{
			SET_VAR( true );
			break;}
		case	6:	{
			SET_VAR( false );
			break;}
		case	7:	{
			SET_VAR( (char)i );
			break;}
		case	8:	{
			SET_VAR( (QRgb)( i*0x010000 + i*0x0100  + i*0x01 ) );
			break;}
		case	9:	{
			SET_VAR( QColor( (QRgb)( i*0x010000 + i*0x0100  + i*0x01 ) ) );
			break;}
		case	10:	{
			SET_VAR( QString::number( i ) );
			break;}
		case	11:	{
			SET_VAR( VAR1_T );
			break;}
		case	12:	{
			SET_VAR( i + 0.1234 );
			break;}
		}
		j++; if ( j >= 13) j = 0;
		if ( b_ok == false ) break;
	}
	TEST_RESULT( b_ok , " - save numerous values" );

	TEST_RESULT( Test_get_numerous( inst ) , " - load numerous values" );

}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void				PgSave::IPgSave_Test_j					(
		IPgSave * inst, int & performed, int & succeded )
{
	QString			Outcm;
	QStringList		sl;
	bool			b_ok;
	bool			b_other_ok;

	for (;;)	{

		int i = inst->getInt( VAR1_T, &b_other_ok );
		if  ( b_other_ok == false ) break;
		if  ( i != 1 ) break;

		b_ok = true; break;
	}
	TEST_RESULT( b_ok , " - value saved across instances" );

	TEST_RESULT( Test_get_numerous( inst ) , " - load numerous values across instances" );

}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void				PgSave::IPgSave_Tests					(
		int & performed, int & succeded )
{
	//QString Outcm;
	performed = 0;
	succeded = 0;

}
/* ========================================================================= */
#endif

/*  CLASS    =============================================================== */
//
//
//
//
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
